package com.huawei.codelab.provider;


import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.PageSliderProvider;

import java.util.List;

public class TabPageSliderProvider extends PageSliderProvider {
    private List<Integer>   layoutFiledIds;
    private AbilitySlice abilitySlice;

    public TabPageSliderProvider(List<Integer> layoutFileIds, AbilitySlice abilitySlice) {
        this.layoutFiledIds =layoutFileIds;
        this.abilitySlice =abilitySlice;

    }


    @Override
    public int getCount() {
        return layoutFiledIds.size();
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {

        Integer id = layoutFiledIds.get(i);
        Component component = LayoutScatter.getInstance(abilitySlice).parse(id, null, false);
        componentContainer.addComponent(component);
        return component;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component)o );
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return true;
    }
}
